﻿using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ImageList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["img"] != null && Request.QueryString["img"].ToString() == "abcdefghikabc")
        {
            DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/Upload"));
            FileInfo[] rgFiles = di.GetFiles("*.bmp").Union(di.GetFiles("*.jpg")).Union(di.GetFiles(".png")).Union(di.GetFiles(".gif")).ToArray();
            images.InnerHtml = "";
            for (int i = 0; i < rgFiles.Length; ++i)
            {
                images.InnerHtml += "<img id=\"img" + i + "\" src=\"Upload/" + rgFiles[i].Name + "\" alt=\"\" style=\"float: left; width: 120px; height: 100px; margin-right:2px; margin-left:2px\" />";
                images.InnerHtml += "<script type='text/javascript'>" +
                                        "$('#img" + i + "').click(function(event){" +
                                        "window.opener.CKEDITOR.tools.callFunction('" + Request.QueryString["CKEditorFuncNum"] + "', 'Upload/" +  rgFiles[i].Name +"');"+
                                        "window.close();" +
                                    "});</script>";
            }
        }
        else
        {
            Response.Redirect("Default.aspx");
        }
    }
}
